import { defineStore } from 'pinia'

const useSettingStore = defineStore('SettingStore', {
  state: () => {
    return {
      isDrawerShow: false, // 左侧菜单收起展开
      active: null, // tabbar选中状态
      themeVal: 'light', // 主题
      isLogin: (sessionStorage.getItem('token') && sessionStorage.getItem('token') != '')  ? true : false, // 是否登录状态
      isGoBackShow: false, // 是否展示返回按钮
      isHeaderShow: true, // 是否展示头部
      isfooterShow: true, // 是否展示tabbar
      isLoadingShow: false, // 是否展示Loading
    }
  },
  actions: {
    handlerSetTurnButtonVal(val: boolean) {
      this.isDrawerShow = val
    },
    handlerSetThemeVal(val: string) {
      this.themeVal = val
    },
    handlerSetActive(val: number) {
      this.active = val
    },
    handlerSetIsLogin(val: boolean) {
      this.isLogin = val
    },
    handlerGoBackShow(val: boolean) {
      this.isGoBackShow = val
    },
    handlerHeaderShow(val: boolean) {
      this.isHeaderShow = val
    },
    handlerFooterShow(val: boolean) {
      this.isfooterShow = val
    },
    handlerLoadingShow(val: boolean) {
      this.isLoadingShow = val
      if (this.isLoadingShow) {
        setTimeout(() => {
          this.isLoadingShow = false
        }, 10000)
      }
    },
  }
})

export default useSettingStore